const { getParkings, updataAuditParkings, getParkingsById, addParkings, deleteParkings, deleteParkingsById,
    confirmChange, getAll, getListById, changeParkingState, backParking } = require("../dao/parkingsDao");

//渲染(出租人)
module.exports.getParkingsById = async function (params) {
    const data = await getParkingsById(params);
    return {
        message: "渲染成功",
        status: 1,
        data
    }
}

//渲染(管理员)
module.exports.getParkings = async function (params) {
    const data = await getParkings(params);
    return {
        message: "渲染成功",
        status: 1,
        data
    }
}

//增加
module.exports.addParkings = async function (parkings) {
    const data = await addParkings(parkings);
    console.log("2增加", data);
    if (data) {
        return {
            message: '添加成功',
            status: 1,
            data: data
        }
    } else {
        return {
            message: '添加失败',
            status: 0,

        }
    }
}
//修改
module.exports.confirmChange = async function ({ _id, address, number, property, cycle, price }) {
    const data = await confirmChange({ _id, address, number, property, cycle, price });
    return {
        msg: "修改成功",
        status: 1,
        data: data
    }
}
//删除(出租方)
module.exports.deleteParkingsById = async function (_id) {
    const data = await deleteParkingsById(_id);
    if (data.n) {
        return {
            status: 1,
            message: "订单数据删除成功",
            data: data
        }
    } else {
        return {
            status: 0,
            message: "订单数据删除失败",
        }
    }
}
//删除(管理员)
module.exports.deleteParkings = async function (_id) {
    const data = await deleteParkings(_id);
    if (data.n) {
        return {
            status: 1,
            message: "订单数据删除成功",
            data: data
        }
    } else {
        return {
            status: 0,
            message: "订单数据删除失败",
        }
    }
}

//修改审核状态
module.exports.updataAuditParkings = async ({ _id, state }) => {
    const data = await updataAuditParkings({ _id, state });
    if (data.nModified === 1) {
        return {
            message: '状态修改成功',
            status: 1
        }
    } else {
        return {
            message: '状态修改失败',
            status: 0
        }
    }
}


//获取所有数据
module.exports.getAll = async (code) => {
    const data = await getAll(code);
    return {
        message: '获取数据成功',
        data,
        status: 1,
    }
}


//通过id获得数据
module.exports.getListById = async (id) => {
    const data = await getListById(id);
    return {
        message: '获取数据成功',
        data,
        status: 1,
    }
}


//购买车位后修改状态
module.exports.changeParkingState = async (id) => {
    const data = await changeParkingState(id);
    return {
        message: '购买成功',
        data,
        status: 1,
    }
}


//归还车位
module.exports.backParking = async (id) => {
    const data = await backParking(id);
    return {
        message: '购买成功',
        data,
        status: 1,
    }
}